home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-05-29 | 6.5 KB | 182 lines | [TEXT/pdos] |
- Apple II
- Technical Notes
- _____________________________________________________________________________
- Developer Technical Support
-
- Apple IIgs
- #71: DA Tips and Techniques
-
- Revised by: Dave "DAs are a significant part of my 'life'" Lyons May 1990
- Written by: Dave Lyons November 1989
-
- This Technical Note presents tips and techniques for writing Desk Accessories.
- Changes since March 1990: Added a caution against drawing during mouseUp
- events in NDAs.
- _____________________________________________________________________________
-
- Classic Desk Accessory Tips and Techniques
-
- Reading the Keyboard
-
- For a CDA that runs only under GS/OS, the Console Driver is the best choice
- for reading from the keyboard. Other CDAs have two cases to deal with: the
- Event Manager may or may not be started. The Text Tools can read the keyboard
- in either case, but you should avoid using the Text Tools whenever possible
- (see Apple IIgs Technical Note #69, The Ins and Outs of Slot Arbitration).
-
- You can call EMStatus to determine whether the Event Manager is started. When
- it is, you can read keypresses by calling GetNextEvent. When the Event
- Manager is not started, you can read keys directly from the keyboard hardware
- by waiting for bit 7 of location $E0C000 to turn on. When it does, the lower
- seven bits represent the key pressed. Once you've detected a keypress, you
- need to write to location $E0C010 to remove the keypress from the buffer.
-
- Alternately, you can use IntSource (in the Miscellaneous Tools) to temporarily
- disable keyboard interrupts and then read the keyboard hardware directly. Be
- sure to reactivate keyboard interrupts if, and only if, they were previously
- enabled.
-
- Just One Page of Stack Space
-
- CDAs normally have only a single page of stack space available to them (256
- bytes at $00/01xx). Your CDA may or may not be able to allocate additional
- stack space from bank 0 during execution. The following code (written for the
- MPW IIgs cross-assembler) shows a safe way to try to allocate more stack space
- and to switch between stacks when the space is available.
-
- If ProDOS 8 is active, your CDA cannot allocate additional space (and there is
- no completely safe way to "borrow" bank 0 space from the ProDOS 8
- application).
-
-
- HowMuchStack gequ $1000 ;try for 4K of stack space
-
- start phd
- phb
- phk
- plb
- pha ;Space for result
- pha
- PushLong #HowMuchStack
- pha
- _MMStartUp
- pla
- ora #$0f00 ;OR in an arbitrary auxiliary ID
- pha
- PushWord #$C001 ;fixed, locked, use specified bank
- PushLong #0 ;(specify bank 0)
- _NewHandle
- tsc
- sta theOldStack
- bcs NoStackSpace ;still set from _NewHandle
- tcd
- lda [1]
- tcd
- ; clc ;carry is already clear
- adc #HowMuchStack-1
- NoStackSpace pha
- ldx #$fe
- keepStack lda >$000100,x
- sta stackImage,x
- dex
- dex
- bpl keepStack
- pla
- tcs
- jsl RealCDAentry ;carry is clear if large stack available
- php
- php
- pla
- sta pRegister
- sei
- ldx #$fe
-
- restoreStack lda stackImage,x
- sta >$000100,x
- dex
- dex
- bpl restoreStack
- lda theOldStack
- tcs
- lda pRegister
- pha
- plp
- plp
-
- lda 1,s
- ora 3,s
- beq noDispose
- _DisposeHandle
- bra Exit
- noDispose pla
- pla
-
-
- Exit plb
- pld
- rtl
-
- pRegister ds 2
- theOldStack ds 2
- stackImage ds.b 256
-
- When this routine calls RealCDAentry, the carry flag is set if no extra stack
- space is available. If the carry is clear, the additional stack space was
- available and the direct-page register points to the bottom of that space.
-
- RealCDAentry bcs smallStack ;if c set, only 1 page of stack is available
- ... ; put something interesting here
- rtl
-
- smallStack _SysBeep
- rtl
-
- Note that interrupts are disabled while the page-one stack is being restored;
- they are reenabled (if they were originally enabled) only after the stack
- pointer is safely back in page one.
-
-
- New Desk Accessory Tips and Techniques
-
- NDAs May Not Receive Apple- Keystrokes
-
- NDAs are not guaranteed to receive key-down events with the Apple key down.
- It is possible that future System Software will pass keystrokes directly to
- the application when the Apple key is down, even if a NDA window is in front.
-
- Calling InstallNDA From Within an NDA
-
- It is possible to write an NDA that installs other NDAs. However, with System
- Software 5.0 and later, InstallNDA returns an error when called from an NDA.
- When your NDA has control because the Desk Manager called one of your NDA's
- entry points, the Desk Manager's data structures are already in use, so
- InstallNDA is unable to modify them.
-
- The solution is to use SchAddTask in the Scheduler to postpone the InstallNDA
- call until the system is not busy. Remember that the Bank and Direct Page
- registers are not defined when your scheduled task is executed.
-
- Processing mouseUp events
-
- When an NDA's action routine receives a mouseUp event, it is not always safe
- for the NDA to draw in its window.
-
- For example, when the user drags an NDA window, the NDA receives the mouseUp
- before the window is actually moved, and before DragWindow erases the outline
- of the new window position, which may overlap the window's content. In
- addition, when the user chooses a menu item, the front NDA receives the
- mouseUp before the menu's image is removed, and the image may overlap the
- NDA's window. In either case, drawing in the window makes a mess.
-
- The solution is to avoid drawing in direct response to a mouseUp. Instead,
- invalidate part of the window to force an update event to happen later.
-
-
- Further Reference
- _____________________________________________________________________________
- o Apple IIGS Toolbox Reference, Volumes 1 & 3
- o GS/OS Reference
- o Apple IIGS Hardware Reference
- o Apple IIGS Technical Note #69, The Ins and Outs of Slot Arbitration
-
-